﻿using FormExample.weakReference;
using HB.MsgBus;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
public delegate void changetext(string text);
namespace FormExample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            MsgBus.RegsterUIThread();
            
               
           
            MsgBus.SubscribeOnUIThread<changetext>(t =>
            {
                this.Text = t;
            });
            //MsgBus.Subscribe<changetext>(t =>
            //{
            //    this.Text = t;
            //});
        }

        private void button1_Click(object sender, EventArgs e)
        {
            weakForm wf = new weakForm();
            wf.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Task.Run(() =>
            {
                MsgBus.Publish<changetext>(t => t("hhhhhhhh"));
            });

        }
    }
}
